package com.tarena.platform.email;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 读取配置文件帮助类
 * 
 * @author tarena
 *
 */
public class PropertiesReader {
	private static Logger log = LoggerFactory.getLogger(PropertiesReader.class);

	public static Map<String, String> cacheProperties(String path) {
		Map<String, String> map = new HashMap<>();
		if (StringUtils.isBlank(path)) {
			log.info("解析配置文件路径为空path={}", path);
			return map;
		}
		log.info("解析配置文件路径path={}", path);
		Properties pro = new Properties();
		try (BufferedReader bf = new BufferedReader(new InputStreamReader(PropertiesReader.class.getClassLoader().getResourceAsStream(path), "utf-8"))) {
			pro.load(bf);
			bf.close();
		} catch (Exception e) {
			log.error("解析配置文件异常error={}", e);
		}
		for (Iterator<?> its = pro.keySet().iterator(); its.hasNext();) {
			String zkey = (String) its.next();
			String value = pro.getProperty(zkey);
			map.put(zkey, value.trim());
			log.info("obj={},value={}",zkey,value);
		}
		return map;
	}
}
